package com.example.splash

import android.app.Application
import android.util.Log
import java.lang.reflect.Field

class App : Application() {

    override fun onCreate() {
        super.onCreate()
        replaceColorField("component_color_theme", R.color.component_color_theme_b)
    }

    private fun replaceColorField(colorName: String, newColorValue: Int) {
        try {
            Log.d(MainActivity.TAG, "replaceColorField: old $colorName value: ${R.color.component_color_theme}")
            // 获取 Color 类的指定静态字段
            val field: Field = R.color::class.java.getField(colorName)
            // 设置字段为可访问
            field.isAccessible = true
            // 替换静态字段的值（null 表示静态字段）
            field.setInt(null, newColorValue)
            // 验证替换是否成功
            val updatedColor = field.getInt(null)
            Log.d(MainActivity.TAG, "replaceColorField: Updated $colorName value: $updatedColor   old:${R.color.component_color_theme}")
        } catch (e: Exception) {
            e.printStackTrace()
            Log.d(MainActivity.TAG, "replaceColorField: $e")
        }
    }

}